﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Weather.Base
{
    public static class WeatherConverter
    {
        //Converts wind speed scale to miles per hour
        public static double WindSpeedConvertToMph(double windSpeed, WindSpeedScale scale)
        {
            switch (scale)
            {
                case WindSpeedScale.Mph:
                    return windSpeed;
                case WindSpeedScale.Kmh:
                    return windSpeed * 0.621371192;
                case WindSpeedScale.Ms:
                    return windSpeed * 2.23693629;
            }
            return windSpeed;
        }

        //Converts wind speed scale to kilometers per hour
        public static double WindSpeedConvertToKmh(double windSpeed, WindSpeedScale scale)
        {
            switch (scale)
            {
                case WindSpeedScale.Mph:
                    return windSpeed * 1.609344;
                case WindSpeedScale.Kmh:
                    return windSpeed;
                case WindSpeedScale.Ms:
                    return windSpeed * 3.6;
            }
            return windSpeed;
        }

        //Converts wind speed scale to meters per second
        public static double WindSpeedConvertToMs(double windSpeed, WindSpeedScale scale)
        {
            switch (scale)
            {
                case WindSpeedScale.Mph:
                    return windSpeed * 0.44704;
                case WindSpeedScale.Kmh:
                    return windSpeed * 0.2777777;
                case WindSpeedScale.Ms:
                    return windSpeed;
            }
            return windSpeed;
        }

        public static WeatherState ConvertSkyCodeToWeatherState(int skycode)
        {
            switch (skycode)
            {
                case 2:
                case 4:
                    return WeatherState.PartlySunny;
                case 3:
                case 6:
                case 34:
                case 35:
                case 36:
                case 38:
                    return WeatherState.PartlyCloud;
                case 8:
                case 7:
                    return WeatherState.Clouds;
                case 11:
                case 37:
                    return WeatherState.Fog;
                case 12:
                case 13:
                case 14:
                    return WeatherState.SmallRain;
                case 19:
                case 20:
                case 21:
                case 22:
                case 23:
                case 24:
                case 25:
                    return WeatherState.Snow;
                case 32:
                    return WeatherState.Wind;
                case 18:
                    return WeatherState.HeavyRain;
                case 15:
                case 16:
                case 17:
                    return WeatherState.Storm;
                default:
                    return WeatherState.Clear;
            }

        }

        public static double FahrenheitToCelsius(double d, TemperatureScale scale = TemperatureScale.Fahrenheit)
        {
            if (scale == TemperatureScale.Celsius)
                return d;
            return (d - 32) * 5 / 9;
        }

        public static double CelsiusToFahrenheit(double d, TemperatureScale scale = TemperatureScale.Celsius)
        {
            if (scale == TemperatureScale.Fahrenheit)
                return d;
            return (d * 9 / 5) + 32; 
        }
    }
}
